package com.itheima.mapper;

import com.itheima.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    @Select("select * from user where username = #{username}")
    User findByUserName(String username);

    @Select("select * from user where id = #{id}")
    User findByUserId(Integer id);

    @Insert("insert into user (username, password, create_time, update_time)" +
    "values(#{username}, #{md5String}, now(), now())")
    void add(String username, String md5String);

    @Update("update user set username = #{username}, password = #{password}, " +
            "create_time = #{createTime}, update_time = #{updateTime}, " +
            "nickname = #{nickname}, email = #{email}, user_pic = #{userPic} " +
            "where id = #{id}")
    void updateUser(User user);

    @Update("update user set user_pic = #{avatarUrl}, update_time = now() where id = #{id}")
    void updateAvatarById(Integer id, String avatarUrl);

    @Update("update user set password = #{password}, update_time = now() where id = #{id}")
    void updateCurUserPassword(Integer id, String password);
}
